<%--
  Created by IntelliJ IDEA.
  User: cos
  Date: 2022/9/29
  Time: 9:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%-- 外部站点 --%>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <%-- 找本服务器的资源 --%>
    <link rel="stylesheet" href="/css/index.css">
</head>
<body>
<h1>index</h1>
<%-- 赋值 --%>
<h1>${msg}</h1>
<h1 id="msg"></h1>
<div>
    <ul id="ul"></ul>
</div>
<button id="btn1">点击</button>
<button id="btn2">点击</button>
<button id="btn3">点击</button>
<button id="btn4">点击4</button>
<div>
    <img src="/img/1.png" alt="">
</div>
<script>
    $(function () {
        $("#btn1").click(function () {
            $.ajax({
                url: "/con/t7",
                type: "get",
                success: function (result) {
                    $("#msg").text(result);
                }
            })
        })
        $("#btn2").click(function () {
            $.ajax({
                url: "/con/t9",
                type: "get",
                dataType: "json",
                success: function (result) {
                    // var u = JSON.parse(result);
                    $("#msg").text(result.name);
                }
            })
        })
        $("#btn3").click(function () {
            $.ajax({
                url: "/con/t10",
                type: "get",
                dataType: "json",
                success: function (result) {
                    // var u = JSON.parse(result);
                    for (let x in result) {
                        $("#ul").append("<li>" + result[x].time + "</li>")
                    }
                }
            })
        })
        $("#btn4").click(function () {
            // 发送json数据必须是post请求
            // js 对象 转为 json字符串发送
            var user = {
                id: 1,
                age: 18,
                name: "王五",
                sex: "男",
                salary: 123.0
            }
            var dada = JSON.stringify(user);
            alert(dada);
            $.ajax({
                url: "/con/t11",
                type: "post",
                data: dada,
                contentType:"application/json", // 设置发送服务器的数据是json数据
                success: function (result) {
                    alert();
                }
            })
        })


    })
</script>
</body>
</html>
